import { loginAPI } from '@/api/user'
export default {
  namespaced: true,
  state: () => {
    return { 
      token: '',
      usermsg:{}
 }
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    setUsermsg(state, usermsg){
      state.usermsg = usermsg
    },
    clearUserInfo(state){
      state.token = ''
      state.usermsg = {}
    }
  },
  actions: {
    async doLogin(ctx, { username, password }) {
      const res = await loginAPI({ username, password })
      ctx.commit('setToken', res.data.token)
    }
  }
}
